#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++) 
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int , int >;
using vec = vector < int >;
using veg = vector < pii >;

int read() {
	int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-', ch = getchar(); 
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return f ? -x : x;
}

const int N = 2e5 + 10;

vec G[N];

int n, m, a[N], b[N];

struct BIT {
	int tr[N];
	void upd(int x, int v) { for(; x <= n; x += x & -x) tr[x] = max(tr[x], v); }
	int query(int x) { int res = 0; for(; x; x -= x & -x) res = max(res, tr[x]); return res; }
} T;

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in; m = in; rep(i, 1, m) a[i] = in, b[i] = in, G[a[i]].pb(b[i]);
	rep(i, 1, n) {
		sort(G[i].begin(), G[i].end(), greater < int >());
		for(auto x : G[i]) {
			int res = T.query(x - 1); //cerr << res << endl;
			res++; T.upd(x, res);
		}
	}
	cout << T.query(n) << endl;
	return 0;
}
